package com.echo.code.arithmetic.chapter05;

import java.util.HashMap;

/**
 * Created by baiyap on 2018/8/14.
 */
public class HashTable {

  public static void main(String[] args) {
    HashMap<String, Float> book = new HashMap<String, Float>() {{
      put("apple", 0.67F);
      put("milk", 1.49F);
      put("avocado", 1.49F);
    }};

    System.out.println(book);
    System.out.println(book.get("avocado"));

    HashMap<String, Boolean> voted = new HashMap<String, Boolean>();
    check_voter(voted, "tom");
    check_voter(voted, "mike");
    check_voter(voted, "mike");
  }

  private static void check_voter(HashMap<String, Boolean> voted, String name) {
    if (voted.containsKey(name)) {
      System.out.println("kick them out!");
    } else {
      voted.put(name, Boolean.TRUE);
      System.out.println("let them vote");
    }
  }
}
